﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CustomControls_LeftMenu : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        List<SessionPermissions> permissions = (List<SessionPermissions>)Session[GlobalNames.UserPermissions];
        string url = this.Page.Request.Url.ToString().ToLower();
        if (url.Contains("/Configuracion/".ToLower()))
        {
            bool flag = false;
            foreach (SessionPermissions s in permissions)
            {
                if (s.ModuleId == (long)GlobalEnums.Modules.Productos && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtProducts.Visible = true;
                }
                if (dtProducts.Visible == true)
                {
                    break;
                }
            }
            
            if (url.Contains("/Productos/".ToLower())) {
                dtProducts.Attributes.Add("class", "selected");
            }
            
            foreach (SessionPermissions s in permissions)
            {
                if (s.ModuleId == (long)GlobalEnums.Modules.Usuarios && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtUsers.Visible = true;
                }
                if (dtUsers.Visible == true)
                {
                    break;
                }
            }

            if (url.Contains("/Usuarios/".ToLower()))
            {
                dtUsers.Attributes.Add("class", "selected");
            }
            foreach (SessionPermissions s in permissions)
            {
                if (s.ModuleId == (long)GlobalEnums.Modules.Telas && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtFabrics.Visible = true;
                }
                if (dtFabrics.Visible == true)
                {
                    break;
                }
            }

            if (url.Contains("/Telas/".ToLower()))
            {
                dtFabrics.Attributes.Add("class", "selected");
            }
            foreach (SessionPermissions s in permissions)
            {
                if (s.ModuleId == (long)GlobalEnums.Modules.Tallas && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtSize.Visible = true;
                }
                if (dtSize.Visible == true)
                {
                    break;
                }
            }

            if (url.Contains("/Tallas/".ToLower()))
            {
                dtSize.Attributes.Add("class", "selected");
            }

            if (url.Contains("/Modelos/".ToLower()))
            {
                dtModels.Attributes.Add("class", "selected");
            }
            foreach (SessionPermissions s in permissions)
            {
                if (s.ModuleId == (long)GlobalEnums.Modules.Modelos && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtModels.Visible = true;
                }
                if (dtModels.Visible == true)
                {
                    break;
                }
            }
            if (flag)
                divConfiguration.Visible = true;
            
        }
        else if (url.Contains("/Procesos/".ToLower()))
        {
            bool flag = false;
            foreach (SessionPermissions s in permissions)
            {
                if (s.ModuleId == (long)GlobalEnums.Modules.Procesos && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtProcesses.Visible = true;
                }
                if (dtProcesses.Visible == true)
                {
                    break;
                }
            }
            if (flag)
                divProcesses.Visible = true;
            dtProcesses.Attributes.Add("class", "selected");
        }
        else if (url.Contains("/Cortes/".ToLower()))
        {
            bool flag = false;
            foreach (SessionPermissions s in permissions)
            {
                if (s.ModuleId == (long)GlobalEnums.Modules.Cortes && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtProductions.Visible = true;
                }
                if (dtProductions.Visible == true)
                {
                    break;
                }
            }
            if (flag)
                divProduction.Visible = true;
            dtProductions.Attributes.Add("class", "selected");
        }
        else if (url.Contains("/Lavanderia/".ToLower()))
        {
            bool flag = false;
            foreach (SessionPermissions s in permissions)
            {
                if (s.ModuleId == (long)GlobalEnums.Modules.Lavanderia && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtLaundry.Visible = true;
                }
                if (dtLaundry.Visible == true)
                {
                    break;
                }
            }
            if (flag)
                divLaundry.Visible = true;
            dtLaundry.Attributes.Add("class", "selected");
        }
        else if (url.Contains("/Reportes/".ToLower()))
        {
            bool flag = false;
            foreach (SessionPermissions s in permissions)
            {
                if (s.ModuleId == (long)GlobalEnums.Modules.Reporte_Ventas && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtSales.Visible = true;
                }
                if (s.ModuleId == (long)GlobalEnums.Modules.Reporte_Productos && s.PermissionId == (long)GlobalEnums.Permissions.Ver)
                {
                    flag = true;
                    dtRepProducts.Visible = true;
                }
            }
            if (flag)
                divReports.Visible = true;
            if (url.Contains("/Reportes/Ventas".ToLower()))
            {
                dtSales.Attributes.Add("class", "selected");
            }
            else if (url.Contains("/Reportes/Productos".ToLower()))
            {
                dtRepProducts.Attributes.Add("class", "selected");
            }
        }
        
    }
}